﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DataProvider
{
    [Serializable]
    public class SageArgument: IComparable<SageArgument>
    {
        private ParameterInfo s;

        public SageArgument()
        {
        }

        public SageArgument(ParameterInfo s)
        {
            this.s = s;

            Name = s.Name;
            Type = s.ParameterType.Name;
            Qualifier = GetQualifier(s);
        }

        private string GetQualifier(ParameterInfo s)
        {
            StringBuilder sb = new StringBuilder();
            if (s.IsIn) sb.Append("In,");
            if (s.IsOptional) sb.Append("Optional,");
            if (s.IsOut) sb.Append("Out,");
            if (s.IsRetval) sb.Append("Retval,");
            if (s.IsLcid) sb.Append("Lcid,");
            return sb.ToString();
        }

        public SageArgument Clone()
        {
            return new SageArgument()
            {
                ArgumentId = this.ArgumentId,
                MethodId = this.MethodId,
                Name = this.Name,
                Type = this.Type,
                Qualifier = this.Qualifier,
            };
        }

        [Key]
        public int ArgumentId { get; set; }

        //Foreign Key
        public int MethodId { get; set; }
        public string Name { get; set; }
        public string Type { get; set; }
        public string Qualifier { get; set; }

        public string Signature { get { return string.Format("{0} {1}", Qualifier, Type); } }

        public override string ToString()
        {
            return string.Format("{0} {1} {2}", Qualifier, Type, Name);
        }

        public int CompareTo(SageArgument other)
        {
            return this.ArgumentId.CompareTo(other.ArgumentId);
        }
    }
}
